﻿Imports System.Data
Imports System.Data.SqlClient

Public Class RecursosHumanos

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select * from trabajador where rut_trabajador='" & TextBox13.Text & "-" & TextBox12.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            Label37.Text = tabla.Rows(0)("nombre")
            Label35.Text = tabla.Rows(0)("direccion")
            Label34.Text = tabla.Rows(0)("telefono")
            Label33.Text = tabla.Rows(0)("area")
            Label32.Text = tabla.Rows(0)("sueldo")

        Catch ex As Exception
            MsgBox("Usuario no registrado", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = "" Or TextBox9.Text = "" Then
            MsgBox("No pueden haber campos vacios!", MsgBoxStyle.Information, "Atencion")
        Else
            Try
                Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
                Dim sql As String = "insert into trabajador values ('" & TextBox1.Text & "-" & TextBox4.Text & "','" & TextBox8.Text & "','" & TextBox2.Text & "','" & TextBox1.Text & "-" & TextBox4.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox5.Text & "','" & TextBox9.Text & "');"
                Dim tabla As New DataTable
                Dim adaptador As New SqlDataAdapter(sql, strCon)
                adaptador.Fill(tabla)


                MsgBox("Datos guardados con exito", MsgBoxStyle.Information, "OK")
                TextBox6.Text = ""
                TextBox2.Text = ""
                TextBox5.Text = ""
                TextBox7.Text = ""
                TextBox8.Text = ""
                TextBox9.Text = ""
                TextBox1.Text = ""
                TextBox4.Text = ""

            Catch ex As Exception
                MsgBox("error en los datos", MsgBoxStyle.Critical, "Error")

            End Try
        End If
    End Sub

  
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select * from trabajador where rut_trabajador='" & TextBox11.Text & "-" & TextBox10.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            Label28.Text = tabla.Rows(0)("nombre")
            Label26.Text = tabla.Rows(0)("direccion")
            Label25.Text = tabla.Rows(0)("telefono")
            Label24.Text = tabla.Rows(0)("area")
            Label23.Text = tabla.Rows(0)("sueldo")



        Catch ex As Exception
            MsgBox("Usuario no registrado", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select * from trabajador where rut_trabajador='" & TextBox1.Text & "-" & TextBox4.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            TextBox6.Text = tabla.Rows(0)("numeroserie")
            TextBox2.Text = tabla.Rows(0)("nombre")
            TextBox5.Text = tabla.Rows(0)("direccion")
            TextBox7.Text = tabla.Rows(0)("telefono")
            TextBox8.Text = tabla.Rows(0)("area")
            TextBox9.Text = tabla.Rows(0)("sueldo")

            TextBox1.Enabled = False
            TextBox4.Enabled = False
            TextBox6.Enabled = False

            Me.Button2.Enabled = False
            Me.Button10.Enabled = True
        Catch ex As Exception
            MsgBox("Usuario no registrado", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        TextBox1.Enabled = True
        TextBox4.Enabled = True
        TextBox6.Enabled = True
        TextBox6.Text = ""
        TextBox2.Text = ""
        TextBox5.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
        TextBox1.Text = ""
        TextBox4.Text = ""

        Me.Button2.Enabled = True
        Me.Button10.Enabled = False
    End Sub

   
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim X As MsgBoxResult
        X = MsgBox("Esta seguro de despedir al empleado? (los cambios seran permanentes)", MsgBoxStyle.YesNo, "Atencion")
        If X = MsgBoxResult.Yes Then
            Try
                Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
                Dim sql As String = "delete trabajador where rut_trabajador='" & TextBox11.Text & "-" & TextBox10.Text & "';"
                Dim tabla As New DataTable
                Dim adaptador As New SqlDataAdapter(sql, strCon)
                adaptador.Fill(tabla)
                MsgBox("Despedido!", MsgBoxStyle.Information, "OK")
                Label23.Text = "**********************"
                Label24.Text = "**********************"
                Label25.Text = "**********************"
                Label26.Text = "**********************"
                Label28.Text = "**********************"


            Catch ex As Exception
                MsgBox("Usuario no registrado", MsgBoxStyle.Critical, "Error")

            End Try
        End If

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Main.WindowState = FormWindowState.Normal
        Me.Close()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Main.WindowState = FormWindowState.Normal
        Me.Close()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Main.WindowState = FormWindowState.Normal
        Me.Close()
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = "" Or TextBox9.Text = "" Then
            MsgBox("No pueden haber campos vacios!", MsgBoxStyle.Information, "Atencion")
        Else
            Try
                Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
                Dim sql As String = "update trabajador set nombre='" & TextBox2.Text & "', direccion='" & TextBox5.Text & "' telefono='" & TextBox7.Text & "', area='" & TextBox8.Text & "', sueldo='" & TextBox9.Text & "' where rut_trabajador ='" & TextBox1.Text & "-" & TextBox4.Text & "';"
                Dim tabla As New DataTable
                Dim adaptador As New SqlDataAdapter(sql, strCon)
                adaptador.Fill(tabla)


                MsgBox("Datos guardados con exito", MsgBoxStyle.Information, "OK")
                TextBox6.Text = ""
                TextBox2.Text = ""
                TextBox5.Text = ""
                TextBox7.Text = ""
                TextBox8.Text = ""
                TextBox9.Text = ""
                TextBox1.Text = ""
                TextBox4.Text = ""

                TextBox1.Enabled = True
                TextBox4.Enabled = True
                TextBox6.Enabled = True

                Me.Button2.Enabled = False
                Me.Button10.Enabled = True

            Catch ex As Exception
                MsgBox("error en los datos", MsgBoxStyle.Critical, "Error")

            End Try
        End If
    End Sub
End Class